import os


def getenv_boolean(var_name, default_value=False):
    result = default_value
    env_value = os.getenv(var_name)
    if env_value is not None:
        result = env_value.upper() in ("TRUE", "1")
    return result


API_V1_STR = "/api/v1"
SECRET_KEY=''
# SECRET_KEY = os.getenvb(b"SECRET_KEY")
if not SECRET_KEY:
    SECRET_KEY = os.urandom(32)

ACCESS_TOKEN_EXPIRE_MINUTES = 60 * 24 * 8  # 60 minutes * 24 hours * 8 days = 8 days

# SERVER_NAME = os.getenv("SERVER_NAME")
SERVER_NAME="localhost:8080"
# SERVER_HOST = os.getenv("SERVER_HOST")
SERVER_HOST = "127.0.0.1:8003"
#配置跨域问题
BACKEND_CORS_ORIGINS='*'
# BACKEND_CORS_ORIGINS = os.getenv(    "BACKEND_CORS_ORIGINS")  # a string of origins separated by commas, e.g: "http://localhost, http://localhost:4200, http://localhost:3000, http://localhost:8080, http://local.dockertoolbox.tiangolo.com"
PROJECT_NAME = 'guard'
SENTRY_DSN = 'asdfasdfasdgfg'

# POSTGRES_SERVER = "localhost:3306"
# POSTGRES_USER = "root"
# POSTGRES_PASSWORD = "mnbvcxz123"
# POSTGRES_DB = "guard"
# POSTGRES_SERVER = os.getenv("POSTGRES_SERVER")
# POSTGRES_USER = os.getenv("POSTGRES_USER")
# POSTGRES_PASSWORD = os.getenv("POSTGRES_PASSWORD")
# POSTGRES_DB = os.getenv("POSTGRES_DB")
# SQLALCHEMY_DATABASE_URI = (
#     f"postgresql://{POSTGRES_USER}:{POSTGRES_PASSWORD}@{POSTGRES_SERVER}/{POSTGRES_DB}"
# )
# 屏蔽以下（mysql数据库）
# SQLALCHEMY_DATABASE_URI = (
#     f"mysql+pymysql://{POSTGRES_USER}:{POSTGRES_PASSWORD}@{POSTGRES_SERVER}/{POSTGRES_DB}"
# )
# 使用SQLite数据库（不用安装，系统自带）
SQLALCHEMY_DATABASE_URI = (
    f"sqlite:///test.db"
)
SMTP_TLS = getenv_boolean("SMTP_TLS", True)
SMTP_PORT = None
_SMTP_PORT = os.getenv("SMTP_PORT")
if _SMTP_PORT is not None:
    SMTP_PORT = int(_SMTP_PORT)
SMTP_HOST = os.getenv("SMTP_HOST")
SMTP_USER = os.getenv("SMTP_USER")
SMTP_PASSWORD = os.getenv("SMTP_PASSWORD")
EMAILS_FROM_EMAIL = os.getenv("EMAILS_FROM_EMAIL")
EMAILS_FROM_NAME = PROJECT_NAME
EMAIL_RESET_TOKEN_EXPIRE_HOURS = 48
EMAIL_TEMPLATES_DIR = "/app/app/email-templates/build"
EMAILS_ENABLED = SMTP_HOST and SMTP_PORT and EMAILS_FROM_EMAIL

# FIRST_SUPERUSER = os.getenv("FIRST_SUPERUSER")
# FIRST_SUPERUSER_PASSWORD = os.getenv("FIRST_SUPERUSER_PASSWORD")
FIRST_SUPERUSER = r"cs@cc.com"
FIRST_SUPERUSER_PASSWORD = "admin1234"

USERS_OPEN_REGISTRATION = getenv_boolean("USERS_OPEN_REGISTRATION")

EMAIL_TEST_USER = "test@example.com"
